/**
 * iview table 配置，需将当前的组件引入进来，否则无法调用当前当前组件的method
 * 借用中间变量table,在挂载组件时将上下文引入进来
 * @author sangtao
 * @type {{table: {}, premisesColumns: *[]}}
 */
var show = false;
var domainUrl = window.location.href;
var linkageShowFlag = false;
if (domainUrl.indexOf("linkage") >= 0) {
  linkageShowFlag = true;
}

function fmtDate(obj) {
  if (obj) {
    var date = new Date(obj);
    var y = 1900 + date.getYear();
    var m = "0" + (date.getMonth() + 1);
    var d = "0" + date.getDate();

    var h = date.getHours();
    h = h < 10 ? "0" + h : h;

    var minute = date.getMinutes();
    minute = minute < 10 ? "0" + minute : minute;
    var second = date.getSeconds();
    second = second < 10 ? "0" + second : second;

    return (
      y +
      "-" +
      m.substring(m.length - 2, m.length) +
      "-" +
      d.substring(d.length - 2, d.length) +
      " " +
      h +
      ":" +
      minute +
      ":" +
      second
    );
  } else {
    return "";
  }
}

var config = {
  table: {},
  premisesColumns: [
    { type: "selection", key: "id", width: 50, fixed: "left", align: "center" },
    {
      type: "index",
      title: "序号",
      key: "",
      width: 65,
      fixed: "left",
      align: "center",
    },
    {
      title: "楼盘名称",
      key: "name",
      width: 330,
      align: "left",
      fixed: "left",
      render: (h, params) => {
        return h("div", [
          h("span", { style: { marginRight: "5px" } }, params.row.name),
          params.row.sysId != null
            ? h(
                "Tag",
                {
                  props: {
                    color: "green",
                    marginLeft: "5px;",
                  },
                },
                "已推送"
              )
            : "",
          params.row.mainPush == 2
            ? h(
                "Tag",
                {
                  props: {
                    color: "blue",
                  },
                },
                "主推"
              )
            : "",
        ]);
      },
    },
    {
      title: "驻守人员",
      key: "partnerName",
      width: 150,
      align: "left",
      ellipsis: "true",
      render(h, params) {
        return h(
          "a",
          {
            attrs: {
              title: params.row.hotLinePartnerName
                ? params.row.hotLinePartnerName +
                  (params.row.partnerName ? "," : "") +
                  params.row.partnerName
                : params.row.partnerName,
            },
          },
          [
            h(
              "span",
              {
                style: {
                  color: "#3399CC",
                },
              },
              params.row.hotLinePartnerName
            ),
            params.row.hotLinePartnerName && params.row.partnerName ? "," : "",
            h("span", params.row.partnerName),
          ]
        );
      },
    },
    // {title:'楼盘标签',key:'codeName',width:300,align:'center'},
    {
      title: "楼盘状态",
      key: "premisesStatusCN",
      width: 95,
      align: "center",
      render: (h, params) => {
        return h("div", [
          h("span", params.row.premisesStatusCN),
          h(
            "a",
            {
              style: {
                color: "#F87242",
                display: params.row.premisesStatus == 2 ? "" : "none",
              },
              on: {
                click: () => {
                  config.table.showPremisesStatus(params.row.remark);
                },
              },
            },
            "?"
          ),
        ]);
      },
    },
    { title: "销售状态", key: "saleStatusName", width: 95, align: "center" },
    { title: "结佣方式", key: "commissionWay", width: 95, align: "center" },
    {
      title: "最短报备时间",
      key: "specialTime",
      width: 135,
      align: "center",
      render: (h, params) => {
        return h(
          "div",
          config.table.setProtectTime(
            params.row.specialTime,
            params.row.specialTimeType
          )
        );
      },
      renderHeader(h) {
        return h("div", [
          h(
            "span",
            {
              style: {
                marginRight: "5px",
              },
            },
            "最短报备时间"
          ),
          h(
            "a",
            {
              style: {
                color: "#F87242",
                textDecorationLine: "underline",
              },
              on: {
                click: () => {
                  config.table.showExplain(1);
                },
              },
            },
            "?"
          ),
        ]);
      },
    },
    {
      title: "到访延长时间",
      key: "visitProtect",
      width: 135,
      align: "center",
      render: (h, params) => {
        return h(
          "div",
          params.row.visitProtect
            ? config.table.setProtectTime(
                params.row.visitProtect,
                params.row.visitProtectType
              )
            : ""
        );
      },
      renderHeader(h) {
        return h("div", [
          h(
            "span",
            {
              style: {
                marginRight: "5px",
              },
            },
            "到访延长时间"
          ),
          h(
            "a",
            {
              style: {
                color: "#F87242",
                textDecorationLine: "underline",
              },
              on: {
                click: () => {
                  config.table.showExplain(2);
                },
              },
            },
            "?"
          ),
        ]);
      },
    },
    {
      title: "交易延长时间",
      key: "saveDays",
      width: 135,
      align: "center",
      render: (h, params) => {
        return h(
          "div",
          params.row.saveDays
            ? config.table.setProtectTime(
                params.row.saveDays,
                params.row.saveDaysType
              )
            : ""
        );
      },
      renderHeader(h) {
        return h("div", [
          h(
            "span",
            {
              style: {
                marginRight: "5px",
              },
            },
            "交易延长时间"
          ),
          h(
            "a",
            {
              style: {
                color: "#F87242",
                textDecorationLine: "underline",
              },
              on: {
                click: () => {
                  config.table.showExplain(3);
                },
              },
            },
            "?"
          ),
        ]);
      },
    },
    // {title:'均价(元/平米)',key:'averagePrice',width:150,align:'center'},
    // {title:'物业费',key:'propertyCharges',width:100,align:'center'},
    { title: "项目总监", key: "chief", width: 95, align: "center" },
    { title: "项目经理", key: "manager", width: 95, align: "center" },
    {
      title: "操作",
      key: "action",
      align: "center",
      fixed: "right",
      width: 400,
      render: (h, params) => {
        return h("div", [
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                display:
                  config.table.userAuthResources.indexOf(
                    "menu_0004_0001_0005"
                  ) >= 0
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.toPremisesSaleStatus(
                    params.row.id,
                    params.row.saleStatus
                  );
                },
              },
            },
            "销售状态变更"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                display:
                  config.table.userAuthResources.indexOf(
                    "menu_0004_0001_0006"
                  ) >= 0
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.toPremisesAudit(params.row.id);
                },
              },
            },
            "审核"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                display: linkageShowFlag ? "" : "none",
              },
              on: {
                click: () => {
                  config.table.changeShelvesStatus(
                    params.row.id,
                    params.row.shelvesStatus
                  );
                },
              },
            },
            params.row.shelvesStatus == "1" ? "下架" : "上架"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                display:
                  config.table.userAuthResources.indexOf(
                    "menu_0004_0001_0007_0001"
                  ) >= 0
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.setAdviser(params.row);
                },
              },
            },
            "置业顾问"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                display:
                  config.table.userAuthResources.indexOf(
                    "menu_0004_0001_0008"
                  ) >= 0
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.toDistributePremises(params.row.id);
                },
              },
            },
            "指定分销商"
          ),
          h(
            "Dropdown",
            {
              props: {
                transferClassName: "premiseDropdown",
              },
            },
            [
              h(
                "Button",
                { props: { type: "primary", size: "small" } },
                "楼盘操作"
              ),
              h(
                "DropdownMenu",
                {
                  slot: "list",
                  textAlign: "center",
                },
                [
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          config.table.userAuthResources.indexOf(
                            "menu_0004_0001_0009"
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.toPremisesDetail(params.row.id);
                            },
                          },
                        },
                        "查看"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          config.table.userAuthResources.indexOf(
                            "menu_0004_0001_0010"
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.toPremisesEdit(params.row.id);
                            },
                          },
                        },
                        "编辑"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          config.table.userAuthResources.indexOf(
                            "menu_0004_0001_0011"
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.deletePremises(params.row.id);
                            },
                          },
                        },
                        "删除"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          config.table.userAuthResources.indexOf(
                            "menu_0003_0001_0011"
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.setDefend(params.row);
                            },
                          },
                        },
                        "设置驻守人"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          config.table.userAuthResources.indexOf(
                            "menu_0004_0001_0013"
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.setReferrer(params.row);
                            },
                          },
                        },
                        "设置推荐人"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          config.table.userAuthResources.indexOf(
                            "menu_0004_0001_0012"
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.showReportModel(params.row.id);
                            },
                          },
                        },
                        "报备模板"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display: params.row.saleStatus == 1 ? "" : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.setMainPush(
                                params.row.id,
                                params.row.mainPush
                              );
                            },
                          },
                        },
                        params.row.mainPush == 1 || params.row.mainPush == null
                          ? "主推楼盘"
                          : "取消主推"
                      ),
                    ]
                  ),
                ]
              ),
            ],
            {
              props: {
                placement: "bottom",
              },
            }
          ),
        ]);
      },
    },
  ],

  cusPreColumns: [
    {
      type: "selection",
      fixed: "left",
      width: 40,
      align: "center",
      className: "tableTdLess",
      render: (h, params) => {
        // return h('div',params.row.reportType == '经纪人报备'?params.row.staffPhone:params.row.assistantPhone)
      },
    },
    //  {type: 'index',title:'序号',key:'',fixed:'left',width:70,align:'center'},
    {
      title: "楼盘名称",
      key: "premisesName",
      fixed: "left",
      width: 120,
      align: "center",
      className: "tableTdLess",
    },
    {
      title: "客户姓名",
      key: "name",
      fixed: "left",
      width: 100,
      align: "center",
      className: "tableTdLess",
    },
    {
      title: "客户电话",
      key: "mobile",
      fixed: "left",
      width: 110,
      align: "center",
      className: "tableTdLess",
    },
    {
      title: "经纪人姓名",
      key: "staffName",
      fixed: "left",
      width: 100,
      align: "center",
      className: "tableTdLess",
    },
    {
      title: "经纪人电话",
      key: "staffPhone",
      fixed: "left",
      width: 110,
      align: "center",
      className: "tableTdLess",
    },
    {
      title: "报备状态",
      key: "cusNewStatusName",
      width: 115,
      align: "center",
      render: (h, params) => {
        return h("div", [
          h(
            "Tag",
            {
              props: {
                color: "green",
              },
            },
            params.row.cusNewStatusName
          ),
        ]);
      },
    },
    {
      title: "交易状态",
      key: "confirmStatusName",
      width: 110,
      align: "center",
      render: (h, params) => {
        return h("div", [
          h(
            "Tag",
            {
              props: {
                color: "green",
              },
            },
            params.row.confirmStatusName
          ),
        ]);
      },
    },
    {
      title: "按揭状态",
      key: "mortgageStatusName",
      width: 100,
      align: "center",
    },
    {
      title: "首付交齐",
      key: "payFinish",
      width: 100,
      align: "center",
      render: (h, params) => {
        return h(
          "div",
          params.row.payFinish === "1"
            ? "是"
            : params.row.payFinish === "0"
            ? "否"
            : ""
        );
      },
    },
    { title: "经纪公司", key: "staffCompanyName", width: 150, align: "center" },
    { title: "上级部门", key: "staffStoreName", width: 150, align: "center" },
    {
      title: "本级部门",
      key: "staffDepartmentName",
      width: 150,
      align: "center",
    },
    //  {title:'机构门店',key:'staffStoreName',width:150,align:'center'},
    //  {title:'机构组别',key:'staffGroupName',width:150,align:'center'},
    //  {title:'渠道经理',key:'principalName',width:115,align:'center'},
    //  {title:'渠道经理电话',key:'principalPhone',width:125,align:'center'},
    {
      title: "报备时间",
      key: "createTime",
      width: 170,
      align: "center",
      render: (h, params) => {
        return h("div", fmtDate(params.row.createTime));
      },
    },
    {
      title: "报备保护时间",
      key: "reportPeriodTime",
      width: 170,
      align: "center",
      render: (h, params) => {
        return h("div", fmtDate(params.row.reportPeriodTime));
      },
    },
    // {title:'期望带看时间',key:'formatHopeVisitTime',width:150,align:'center'},
    {
      title: "实际到访时间",
      key: "visitTime",
      width: 170,
      align: "center",
      render: (h, params) => {
        return h("div", fmtDate(params.row.visitTime));
      },
    },
    { title: "报备类型", key: "reportType", width: 110, align: "center" },
    {
      title: "操作",
      key: "action",
      fixed: "right",
      width: 240,
      className: "tableTdLess",
      align: "center",
      render: (h, params) => {
        return h("div", [
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                marginTop: "5px",
                display:
                  config.table.userAuthResources.indexOf(
                    "menu_0005_0001_0010"
                  ) >= 0
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.toDetail(params.row.id);
                },
              },
            },
            "查看"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                marginTop: "5px",
                display:
                  params.row.customerStatus == 0 &&
                  config.table.userAuthResources.indexOf(
                    config.table.resourcesList.menu_0005_0001_0005
                  ) >= 0
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.audit(params.row.id, "报备审核");
                },
              },
            },
            "报备审核"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                marginTop: "5px",
                display:
                  params.row.customerStatus == 10 &&
                  config.table.userAuthResources.indexOf(
                    config.table.resourcesList.menu_0005_0001_0006
                  ) >= 0
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.audit(
                    params.row.id,
                    "到访审核",
                    params.row.checkSwitch,
                    params.row.lastCheckTime,
                    params.row.premisesId
                  );
                },
              },
            },
            "到访审核"
          ),
          !(params.row.isToM2 && params.row.isToM2 == 1)
            ? h(
                "Button",
                {
                  props: {
                    type: "warning",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px",
                    marginTop: "5px",
                    display:
                      params.row.customerStatus == 6 &&
                      params.row.confirmStatus != 4 &&
                      config.table.userAuthResources.indexOf(
                        config.table.resourcesList.menu_0005_0001_0007
                      ) >= 0
                        ? ""
                        : "none",
                  },
                  on: {
                    click: () => {
                      config.table.changeConfirm(params.row);
                    },
                  },
                },
                "交易审核"
              )
            : "",
          ,
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                marginTop: "5px",
                backgroundColor:
                  params.row.copyCount > 0 ? "#FACD91" : "#FF9900",
                borderColor: params.row.copyCount > 0 ? "#FACD91" : "#FF9900",
              },
              on: {
                click: () => {
                  config.table.toCopy(params.row);
                },
              },
            },
            "复制"
          ),
          h(
            "Dropdown",
            [
              h(
                "Button",
                {
                  props: { type: "primary", size: "small" },
                  style: {
                    marginRight: "5px",
                    marginTop: "5px",
                  },
                },
                "更多"
              ),
              h(
                "DropdownMenu",
                {
                  slot: "list",
                  textAlign: "center",
                },
                [
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          config.table.userAuthResources.indexOf(
                            "menu_0005_0001_0012"
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.toEditCus(
                                params.row.id,
                                params.row.name,
                                params.row.gender,
                                params.row.remark
                              );
                            },
                          },
                        },
                        "编辑"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          config.table.userAuthResources.indexOf(
                            config.table.resourcesList.menu_0005_0001_0004
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.toFollow(
                                params.row.id,
                                params.row.reportType == "经纪人报备"
                                  ? params.row.staffName
                                  : params.row.assistantName,
                                params.row.customerStatus,
                                params.row.confirmStatus,
                                params.row.checkSwitch,
                                params.row.lastCheckTime
                              );
                            },
                          },
                        },
                        "写跟进"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          (params.row.confirmStatus === "2" ||
                            params.row.confirmStatus === "3") &&
                          config.table.userAuthResources.indexOf(
                            "menu_0005_0001_0011"
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.changeInsert(params.row.id);
                            },
                          },
                        },
                        "首付录入"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          (params.row.confirmStatus == 2 ||
                            params.row.confirmStatus == 3) &&
                          config.table.userAuthResources.indexOf(
                            config.table.resourcesList.menu_0005_0001_0008
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.changeMortgage(params.row.id);
                            },
                          },
                        },
                        "按揭状态"
                      ),
                    ]
                  ),
                  h(
                    "DropdownItem",
                    {
                      style: {
                        textAlign: "center",
                        display:
                          params.row.customerStatus != "-1" &&
                          params.row.confirmStatus != "4" &&
                          !params.row.mobileHidden &&
                          params.row.mobile.indexOf("***") >= 0 &&
                          config.table.userAuthResources.indexOf(
                            config.table.resourcesList.menu_0005_0001_0002
                          ) >= 0
                            ? ""
                            : "none",
                      },
                    },
                    [
                      h(
                        "Button",
                        {
                          props: { type: "primary", size: "small" },
                          on: {
                            click: () => {
                              config.table.completePhone(
                                params.row.id,
                                params.row.mobile
                              );
                            },
                          },
                        },
                        "号码补全"
                      ),
                    ]
                  ),
                ]
              ),
            ],
            {
              props: {
                placement: "bottom",
              },
            }
          ),
        ]);
      },
    },
  ],
};
export default {
  config,
};
